<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改')"/>
</head>
<body>
<form action="" class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="id"
                               th:value="${canalConfig.id}" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="title"
                               th:value="${canalConfig.title}" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">实例名称</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="instanceName"
                               th:value="${canalConfig.instanceName}" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">host</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="host" name="host" placeholder="连接地址"
                               th:value="${canalConfig.host}"
                               type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">port</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="port" name="port" placeholder="连接端口"
                               th:value="${canalConfig.port}"
                               type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="userName" name="userName" placeholder="canal-server 连接用户名"
                               th:value="${canalConfig.userName}"
                               type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="password" name="password" placeholder="canal-server 连接密码"
                               th:value="${canalConfig.password}"
                               type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">过滤规则</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="filter" name="filter" placeholder="canal-server 过滤规则"
                               th:value="${canalConfig.filter}"
                               type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">批次取数据量</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="batchSize" name="batchSize" placeholder="批次取数据量"
                               th:value="${canalConfig.batchSize}"
                               type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">消息消费线程数</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="consumerThreadSize" name="consumerThreadSize" placeholder="每次消费消息时线程数量"
                               th:value="${canalConfig.consumerThreadSize}"
                               type="text">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">启用集群</label>
                    <div class="layui-input-block">
                        <input lay-filter="clusterEnabled" name="clusterEnabled" th:checked="${canalConfig.clusterEnabled eq '0'}"
                               title="启用" type="radio" value="1">
                        <input lay-filter="clusterEnabled" name="clusterEnabled" th:checked="${canalConfig.clusterEnabled eq '1'}"
                               title="停用" type="radio" value="0">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">集群zk地址</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="zookeeperAddress" name="zookeeperAddress" placeholder="集群zk地址"
                               th:value="${canalConfig.zookeeperAddress}"
                               type="text">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="pear-btn pear-btn-primary pear-btn-sm" lay-filter="save" lay-submit="" type="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(save)', function (data) {
            data.field.icon = "layui-icon " + data.field.icon;
            $.ajax({
                url: '/canalClient/update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("#table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>